package com.heima.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.common.constants.UserConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.UserRelationDto;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.user.pojos.ApUserFan;
import com.heima.model.user.pojos.ApUserFollow;
import com.heima.user.service.IApUserFollowService;
import com.heima.user.service.UserLoginService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;

/**
 * <p>
 * APP用户关注信息表 前端控制器
 * </p>
 *
 * @author fkn
 * @since 2024-08-21
 */
@RestController
public class ApUserFollowController {

    @Resource
    private IApUserFollowService apUserFollowService;
    @Resource
    private UserLoginService userLoginService;

    @PostMapping("/api/v1/user/user_follow")
    @ApiOperation("用户关注")
    public ResponseResult userFollow(@RequestBody @Valid UserRelationDto dto){
        if (dto.getOperation() == UserConstants.FOLLOW){
            return apUserFollowService.userFollow(dto);
        }else {
            return apUserFollowService.userNotFollow(dto);
        }
    }

    @PostMapping("/is_follow")
    public ResponseResult isFollow(@RequestBody ArrayList<Integer> list){
        Integer userId = list.get(0);
        Integer followId = list.get(1);
        LambdaQueryWrapper<ApUserFollow> condition = new LambdaQueryWrapper<ApUserFollow>()
                .eq(ApUserFollow::getUserId, userId)
                .eq(ApUserFollow::getFollowId, followId);
        ApUserFollow one = apUserFollowService.getOne(condition);
        return ResponseResult.okResult(one != null);
    }

    @PostMapping("/user")
    public String getUser (@RequestBody Integer userId){
        ApUser one = userLoginService.getById(userId);
        return one.getName();
    }
}
